package com.xyzh.stj.sheduled.impl;


import com.xyzh.stj.sheduled.ScheduledService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;

import java.util.concurrent.ScheduledFuture;

@Slf4j
@Component
public class ScheduledServiceImpl implements ScheduledService {

    @Autowired(required = false)
    private TaskScheduler taskScheduler;

    @Override
    public ScheduledFuture sendCronTaskRun(String cron, Runnable runnable) {
        return taskScheduler.schedule(runnable, new CronTrigger(cron));
    }
}
